package cn.fastoo.common.utils;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

/**
 * Created by yangxun on 15/8/20.
 *
 * @author yangxun
 */
public class HttpClientHelper {

    private static CloseableHttpClient client;
    private static PoolingHttpClientConnectionManager connManager;
    private static final int MAX_TOTAL = 100;
    private static final int MAX_PER_ROUTE = 20;

    public static CloseableHttpClient getHttpClient() {
        if (client == null) {
            // 创建
            connManager = new PoolingHttpClientConnectionManager();
            connManager.setMaxTotal(MAX_TOTAL);
            connManager.setDefaultMaxPerRoute(MAX_PER_ROUTE);
            client = HttpClientBuilder.create().setConnectionManager(connManager).build();
        }
        return client;
    }

}
